#include "ThreadPool.h"

int squre(int i)
{
    std::cout << "Hello from task " << i << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "Task " << i << " completed" << std::endl;
    return i * i;
}

int main()
{
    std::cout << "this main thread id is " << std::this_thread::get_id() << std::endl;
    // Create a thread pool with 4 worker threads
    ThreadPool pool(4);

    // Enqueue some tasks
    std::vector<std::future<int>> results;
    for (int i = 1; i < 20; i++)
    {
        // results.emplace_back(pool.enqueue(&squre, i));
        results.emplace_back(pool.enqueue([i]()
                                          {
                            std::cout << "Hello from task " << i << std::endl;
                            std::this_thread::sleep_for(std::chrono::seconds(1));
                            std::cout << "Task " << i << " completed" << std::endl;
                            return i * i; }));
    }

    std::this_thread::sleep_for(std::chrono::seconds(5));
    // Wait for all tasks to complete
    for (auto &result : results)
        std::cout << "Task completed with result: " << result.get() << std::endl;

    return 0;
}
